package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBDDemo6 {
    public static void main(String[] args) {
        try (
                Connection connection = DBUtil.getConnection();
                ){
            Statement statement = connection.createStatement();
            String sql="SELECT t.name,t.gender,c.name,c.floor \n" +
                    "FROM teacher t \n" +
                    "JOIN class c ON t.id = c.teacher_id \n" +
                    "WHERE t.name = '王克晶'";

            ResultSet resultSet=statement.executeQuery(sql);
            while (resultSet.next()) {
                String tName= resultSet.getString("t.name");
                String tGender= resultSet.getString("t.gender");
                String cName= resultSet.getString("c.name");
                String cFloor= resultSet.getString("c.floor");
                System.out.println(tName+","+tGender+","+cName+","+cFloor);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
